package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportDataService.class)
@Transactional
public class ReportDataServiceImpl implements ReportDataService{

    @Autowired
    private MemberService memberService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private SetMealService setMealService;

    @Override
    public Map getBusinessReportData() throws Exception {
        Map<String, Object> hashMap = new HashMap<>();
//                reportDate:null,
        String reportDate = DateUtils.parseDate2String(new Date());
        hashMap.put("reportDate",reportDate);

        //String类型的当天日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());

//                todayNewMember :0,
        Integer todayNewMember=memberService.gettodayNewMember(today);
        hashMap.put("todayNewMember",todayNewMember);

//                totalMember :0,
        Integer totalMember=memberService.gettotalMember();
        hashMap.put("totalMember",totalMember);

        //获取本周第一天的时间
        String thisWeekMonday =DateUtils.parseDate2String( DateUtils.getThisWeekMonday());
//        获取本月第一天的时间
        String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

//                thisWeekNewMember :0,从星期一开始到今天
        Integer thisWeekNewMember=memberService.getNewMemberAfterDay(thisWeekMonday);
        hashMap.put("thisWeekNewMember",thisWeekNewMember);

//                thisMonthNewMember :0,
        Integer thisMonthNewMember=memberService.getNewMemberAfterDay(thisMonthFirstDay);
        hashMap.put("thisMonthNewMember",thisMonthNewMember);

//                todayOrderNumber :0,
        Integer todayOrderNumber=orderService.getTodayOrderNumber(today);
        hashMap.put("todayOrderNumber",todayOrderNumber);

//                todayVisitsNumber :0,
        Integer todayVisitsNumber=orderService.getTodayVisitsNumber(today);
        hashMap.put("todayVisitsNumber",todayVisitsNumber);

//                thisWeekOrderNumber :0,
        Integer thisWeekOrderNumber=orderService.getOrderNumberAfterDate(thisWeekMonday);
        hashMap.put("thisWeekOrderNumber",thisWeekOrderNumber);

//                thisWeekVisitsNumber :0,
        Integer thisWeekVisitsNumber=orderService.getVisitsNumberAfterDate(thisWeekMonday);
        hashMap.put("thisWeekVisitsNumber",thisWeekVisitsNumber);

//                thisMonthOrderNumber :0,
        Integer thisMonthOrderNumber=orderService.getOrderNumberAfterDate(thisMonthFirstDay);
        hashMap.put("thisMonthOrderNumber",thisMonthOrderNumber);

//                thisMonthVisitsNumber :0,
        Integer thisMonthVisitsNumber=orderService.getVisitsNumberAfterDate(thisMonthFirstDay);
        hashMap.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

//                hotSetmeal :[
//        {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
//        {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
//                    ]
        List<Map> hotSetmeal=setMealService.getHotSetmeal();
        hashMap.put("hotSetmeal",hotSetmeal);


        return hashMap;
    }
}
